package opertion;

import book.Book;
import book.BookList;

import java.util.Scanner;
//这里是通过书名来进行借阅图书的
public class BorrowOpertion implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要借阅的书名");
        String name=sc.nextLine();
//        System.out.println("请输入你要借阅书的作者");
//        String author=sc.nextLine();
//        System.out.println("请输入你要借阅书的类型");
//        String type=sc.nextLine();
//        System.out.println("请输入你要借阅书的价格");
//        int price=sc.nextInt();
//        Book book=new Book(name,author,type,price);
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if(bookList.getBooks()[i].getName().equals(name)&& bookList.getBooks()[i].isBorrowed()!=true){
                bookList.getBooks()[i].setBorrowed(true);
                System.out.println("借书成功");
                return;
            }else if(bookList.getBooks()[i].getName().equals(name)&& bookList.getBooks()[i].isBorrowed()==true){
                System.out.println("该书被借出");
                return;
            }
        }
        System.out.println("没有该书");
    }
}
